Multi-Client Network Programming in Python
A TCP socket trivia game where a single server handles multiple clients simultaneously — no threads, just Python's select().
This is a school network programming project — a fully working trivia game over TCP. A Python server accepts connections from multiple clients, authenticates users, serves random questions, tracks scores in real time, and handles clients disconnecting cleanly or abruptly. The core challenge: doing all of this with a single-threaded server using select() for non-blocking I/O multiplexing.
The server loop calls select() each iteration to find which sockets are ready to read or write — handling N clients without spawning a single thread.
chatlib builds and parses fixed-format messages — every packet has a command code, length field, and data payload. Both client and server share the same library.
Users log in with username + password. Scores update live as players answer questions. A leaderboard command returns all scores sorted in real time.
network-campus/
├── server/
│ ├── server_skeleton.py # main server — select() loop, message handlers
│ └── chatlib.py # protocol: build_message / parse_message
└── client/
├── client.py # interactive client with menu
└── chatlib.py # same protocol library (client side)
Start the server in one terminal
python server/server_skeleton.py
Connect a client in a second terminal
python client/client.py
Open more terminals and connect additional clients — the server handles all of them in parallel.
| Key | Action |
|---|---|
| 1 | My Score — see your current score |
| 2 | High Score table — see all players ranked |
| 3 | Quit — logout and close connection |
| 4 | Play — get a trivia question and answer it |
| 5 | Logged Users — see who else is connected right now |